// pages/categories/categories.js
const app=getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    cate_nav_list:[],
    curIndex:0,
    ca_id:0,
    toView:"new",
    loadingTxt: '加载中',
    noMoreData: false,
    page: 1,
    showGoTop: false,
    size: 16,
    detail:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  switchCategory(e){
    const curIndex=e.currentTarget.dataset.id?e.currentTarget.dataset.id:this.data.ca_id;
    var page=this.data.page;
    var size=this.data.size;
    var that=this;
    wx.request({
      url: app.globalData.url +'/index.php?s=api/item/lists',
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        method:'get',
        data: {size:size,page:page,categoryId:curIndex,app_id:10001},
        success: (res) => {
          if(res.data.code==1){
            that.setData({
              detail:res.data.data.list
            })
          }
         
        }
      })
 
  },
  onLoad: function (options) {
    const detail=app.globalData.category;
    this.setData({
      detail
    });
    this.getCategories();
  },

  getCategories:function(){
    var that=this;
    wx.request({
      url: app.globalData.url +'/index.php?s=api/category/index',
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        method:'get',
        data: {app_id:10001},
        success: (res) => {
          if(res.data.code==1){
            that.setData({
              cate_nav_list:res.data.data.list
            })
            that.getStartList(res.data.data.list[0].id);
          }
          
        }
      })
  },

  getStartList:function(id){
    var page=this.data.page;
    var size=this.data.size;
    var that=this;
    wx.request({
      url: app.globalData.url +'/index.php?s=api/item/lists',
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        method:'get',
        data: {size:size,page:page,categoryId:id,app_id:10001},
        success: (res) => {
          if(res.data.code==1){
            that.setData({
              detail:res.data.data.list
            })
          }
         
        }
      })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})